#ifndef _ROB_MOTOR_H
#define _ROB_MOTOR_H

#include <WProgram.h>
#include <avr/io.h>

// motor controller i2c address
#define I2CMCTRL_ADR 0x30 // Address of i2c motor driver


// motor commands and definitions
#define MOT_CMD_SPEED 0x10 // send (MOT_CMD_SPEED | MOT_A_xx | MOT_B_xx, speedA, speedB)
#define MOT_CMD_SENSE 0x20 // send (MOT_CMD_SENSE) 


#define I2CMCTRL_ACK_LEN 3 // we expect 3 bytes from the controller as a response: battery status, Lspeed, RSpeed


// Motor direction control command bits
#define MOT_A_STOP  0x00
#define MOT_A_FWD   0x01
#define MOT_A_REV   0x02
#define MOT_A_BREAK 0x03
#define MOT_B_STOP  0x00
#define MOT_B_FWD   0x04
#define MOT_B_REV   0x08
#define MOT_B_BREAK 0x0c


class CMotor {

public:
  void Begin(void);
  uint8_t update(void);
  uint8_t requestSensors(void);

private:
  uint8_t _lastEngineDirections;
  uint8_t _lastEngineLPower;
  uint8_t _lastEngineRPower;
  uint8_t _mCtrlCmd[3];

};

extern CMotor Motor;




#endif //_ROB_MOTOR_H

